package qf.common.security.configure;

import com.alibaba.fastjson2.JSONObject;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;
import qf.common.core.constant.HttpStatus;
import qf.common.core.utils.WebUtils;
import qf.common.core.web.vo.AjaxResult;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException e) throws IOException, ServletException {
        response.setStatus(HttpStatus.FORBIDDEN); //403
        AjaxResult result = AjaxResult.error(HttpStatus.FORBIDDEN,"账号权限不足，请联系管理员 ");
        WebUtils.renderString(response, JSONObject.toJSONString(result));
    }
}

